#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, LL> PII;
#define x first
#define y second
const int N = 2e5 + 10;
vector<int>g[N];

int n, m, h;

PII fun(vector<int>a)
{
	PII ans;
	sort(a.begin(), a.end());
	int cnt = 0;
	LL sum = 0;
	LL z = 0;
	for (auto x : a) {
		sum += x;
		if (sum <= h) {
			cnt++;
			z += (sum - x);
		}
		else {
			sum -= x;
			break;
		}
	}
	ans.x = cnt;
	ans.y = sum + z;
	return ans;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m >> h;
		for (int i = 1; i <= n; i++)g[i].clear();
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				int x;
				cin >> x;
				g[i].push_back(x);
			}
		}
		int cnt = 0;
		PII ans = fun(g[1]);
		//cout << "==" << endl;
		//cout << ans.x << " " << ans.y << endl;
		for (int i = 2; i <= n; i++) {
			PII x = fun(g[i]);
			if (x.x > ans.x)cnt++;
			else if (x.x == ans.x) {
				if (x.y < ans.y)cnt++;
			}
		}
		//cout << "cnt==";
		cout << cnt + 1 << endl;
	}
	return 0;
}	